package com.yuerenjf.yuerenjinfu.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.yuerenjf.yuerenjinfu.R;

/**
 * Created by Administrator on 2015/10/19.
 */
public class DialogUpdata extends Dialog implements View.OnClickListener {

    TypeCallBack callBack;

    private TextView infoVersionTv;
    private TextView infoContentTv;
    private TextView updataTv;
    private TextView cancelTv;

    public TypeCallBack getCallBack() {
        return callBack;
    }

    public void setCallBack(TypeCallBack callBack) {
        this.callBack = callBack;
    }

    public boolean isAbort() {
        return isAbort;
    }

    public void setAbort(boolean abort) {
        isAbort = abort;
    }

    boolean isAbort;

    public DialogUpdata(Activity context,boolean isAbort) {
        super(context, R.style.dialog);
        this.isAbort=isAbort;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_updata);

        infoVersionTv= (TextView) findViewById(R.id.dialog_updata_info_version_text);
        infoContentTv= (TextView) findViewById(R.id.dialog_updata_info_content_text);
        updataTv= (TextView) findViewById(R.id.dialog_updata_version_text);
        cancelTv= (TextView) findViewById(R.id.dialog_updata_next_text);

        if(isAbort){
            cancelTv.setVisibility(View.GONE);
            setCanceledOnTouchOutside(false);
//            setCancelable(false);
        }else{
            cancelTv.setVisibility(View.VISIBLE);
            setCanceledOnTouchOutside(true);
//            setCancelable(true);
        }
        updataTv.setOnClickListener(this);
        cancelTv.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.dialog_updata_version_text:

                callBack.setUpdata();
                break;
            case R.id.dialog_updata_next_text:
                callBack.setCancel();
                break;
        }
    }

    public void setCotent(String version,String content){
        infoVersionTv.setText("版本号:"+version);
        infoContentTv.setText(content);

    }


    public void showCustomDialog() {
        show();
        Window dialogWindow = getWindow();
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        dialogWindow.setGravity(Gravity.CENTER);
        lp.width = ViewGroup.LayoutParams.WRAP_CONTENT;
        lp.height = ViewGroup.LayoutParams.WRAP_CONTENT;
        dialogWindow.setAttributes(lp);
    }


    public interface TypeCallBack {
        void setCancel() ;
        void setUpdata();
    }
}
